<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise</title>
</head>
<body>
    <button id="submit" style="width: 200px; height: 100px;">Go</button>
</body>
<script>
    const btn = document.querySelector("#submit");
    btn.addEventListener("click", function(){
        const p = new Promise((resolve, reject) => {
            let n = 10;
            if(n < 30) {
                resolve(n);
            } else {
                reject(n);
            }
        });
        p.then((value) => {
            alert("成功" + value);
        }, (reason) => {
            alert("失败" + reason);
        });

    });
</script>
</html>